package net.optix.ip.commands
{
	import com.adobe.cairngorm.business.Responder;
	import com.adobe.cairngorm.commands.Command;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import net.optix.ip.business.*;
	import net.optix.ip.events.AddInventionEvent;
	import net.optix.ip.model.ModelLocator;
	import views.ViewInstance;

	public class AddInventionCommand implements Command, Responder
	{
		// attributes ============================
		private var model : ModelLocator = ModelLocator.getInstance();


		// functions ============================
		public function execute( event:CairngormEvent ) : void
		{
			var myEvent:AddInventionEvent	=	AddInventionEvent(event);
			
			var delegate:InventionDelegate	=	new InventionDelegate();
			delegate.addInvention(this,myEvent.vo);	
		}
		
		//----------------------------------------------------------------------------
		public function onResult( event : * = null ) : void
		{
			try
			{
				var	result:int				=	event.result.result;
				switch(result)
				{
					case -2:
						model.result	=	"Access Denied .";
						break;
					case 0:
						model.result	=	"Program error!";
						break;
					case 1:
						model.result	=	"You have successfully disclosed the new invention !";
						model.view		=	0;
						model.view		=	ViewInstance.ViewInventions;
						model.close			=	"no";
						model.close			=	"yes";
						break;
				}
			}
			catch(error:Error)
			{
				model.result	=	"Program error";
			}
			
			model.bSubmit	=	true;
		}
		
		//----------------------------------------------------------------------------
		public function onFault( event : * = null ) : void
		{
			model.result	=	"Program error";
			model.bSubmit	=	true;
		}
	}
}